/**
 * Definition for a binary tree node.
 * function TreeNode(val) {
 *     this.val = val;
 *     this.left = this.right = null;
 * }
 */
/**
 * @param {TreeNode} root
 * @return {number}
 */
var minDepth = function(root) {
    if(!root)return 0;
    else if(root.right&&!root.left)return minDepth(root.right)+1;
    else if(!root.right&&root.left)return minDepth(root.left)+1;
    else return Math.min(minDepth(root.right)+1,minDepth(root.left)+1);
};